<?php
require("../lib/Loader.php");
Loader::loadClass("Application");
Loader::loadClass("Db");
Loader::loadClass("Config");
Loader::loadClass("Logger");
Loader::loadClass("Profiler");
Loader::loadClass("TemplateTree");
Loader::loadClass("Template");
Config::init();
Logger::init();
//$app = new Application();
//$app->run();
$db = new Db();
$statement = $db->getStatement();
//$statement->insertStatement("user", array("username"=>"administrator"));
//$statement->deleteStatement("user", array("id"=>10));
//$statement->updateStatement("user", array("id"=>9), array("username"=>"thuongnh"));
$statement->selectStatement("user");
$result = $db->query($statement, Db::FETCH_ASSOC);
//echo "<ul>";
//foreach ($result as $row){
//    echo "<li>".$row['id']." - ".$row['username']."</li>";
//}
//echo "</ul>";
//$db->execute($statement);
//echo $db->lastInsertId();
$db->close();
$tree=new TemplateTree();
$template = new Template();

Profiler::start("main");

$tree->import("footer.html", "footer");
$tree->setVariable("title", "Test my template");
$tree->setVariable("header", "Hello world!");

foreach ($result as $row){
    $loop = $tree->addSection("loop");
    $loop->setVariable("id", $row['id']);
    $loop->setVariable("username", $row['username']);
}

echo $template->render($tree, "../app/view/test.html");
Profiler::end("main");
Profiler::output();

//print_r($test);

Logger::finish();
